import 'package:cms/models/term.dart';
import 'package:common/dio/model.dart';

class SingleModel extends BaseModel {
  int? id;
  String? title;
  SingleActions? actions;
  String? excerpt;
  String? status;
  String? type;
  Author? author;
  String? cover;
  List<WpTerm>? categories;
  List<String>? images;
  Date? date;
  String? permalink;
  String? commentCount;
  String? commentStatus;
  String? content;
  RowListOptions? rowListOptions;

  SingleModel({
    this.id,
    this.title,

    this.excerpt,
    this.status,
    this.type,
    this.author,
    this.cover,
    this.categories,
    this.images,
    this.content,
    this.date,
    this.permalink,
    this.commentCount,
    this.commentStatus,
    this.rowListOptions,
  });

  SingleModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    title = json['title'];

    excerpt = json['excerpt'];
    status = json['status'];
    type = json['type'];
    author = json['author'] != null ? Author.fromJson(json['author']) : null;
    cover = json['cover'];
    content = json['content'];
    if (json['categories'] != null) {
      categories = <WpTerm>[];
      json['categories'].forEach((v) {
        categories!.add(WpTerm.fromJson(v));
      });
    }
    if (json['images'] != null) {
      images = <String>[];
      json['images'].forEach((v) {
        images!.add(v);
      });
    }
    actions = json['actions'] != null
        ? SingleActions.fromJson(json['actions'])
        : null;

    date = json['date'] != null ? Date.fromJson(json['date']) : null;
    permalink = json['permalink'];
    commentCount = json['comment_count'];
    commentStatus = json['comment_status'];
    rowListOptions = json['row_list_options'] != null
        ? RowListOptions.fromJson(json['row_list_options'])
        : null;
  }
  @override
  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['title'] = title;
    data['content'] = content;
    data['excerpt'] = excerpt;
    data['status'] = status;
    data['type'] = type;
    if (author != null) {
      data['author'] = author!.toJson();
    }
    data['cover'] = cover;
    if (categories != null) {
      data['categories'] = categories!.map((v) => v.toJson()).toList();
    }
    if (images != null) {
      data['images'] = images!.map((v) => v).toList();
    }
    if (date != null) {
      data['date'] = date!.toJson();
    }
    data['permalink'] = permalink;
    data['comment_count'] = commentCount;
    data['comment_status'] = commentStatus;
    if (rowListOptions != null) {
      data['row_list_options'] = rowListOptions!.toJson();
    }
    if (actions != null) {
      data['actions'] = actions!.toJson();
    }
    return data;
  }
}

class Author {
  String? id;
  String? name;
  String? slug;
  String? avatar;

  Author({this.id, this.name, this.slug, this.avatar});

  Author.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    slug = json['slug'];
    avatar = json['avatar'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['name'] = name;
    data['slug'] = slug;
    data['avatar'] = avatar;
    return data;
  }
}

class Date {
  String? created;
  String? createdGmt;
  String? modified;
  String? modifiedGmt;

  Date({this.created, this.createdGmt, this.modified, this.modifiedGmt});

  Date.fromJson(Map<String, dynamic> json) {
    created = json['created'];
    createdGmt = json['created_gmt'];
    modified = json['modified'];
    modifiedGmt = json['modified_gmt'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['created'] = created;
    data['created_gmt'] = createdGmt;
    data['modified'] = modified;
    data['modified_gmt'] = modifiedGmt;
    return data;
  }
}

class RowListOptions {
  List<String>? listDisplayData;
  String? imagePosition;
  String? imageDisplay;

  RowListOptions({this.listDisplayData, this.imagePosition, this.imageDisplay});

  RowListOptions.fromJson(Map<String, dynamic> json) {
    listDisplayData = json['list_display_data'].cast<String>();
    imagePosition = json['image_position'];
    imageDisplay = json['image_display'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['list_display_data'] = listDisplayData;
    data['image_position'] = imagePosition;
    data['image_display'] = imageDisplay;
    return data;
  }
}

class SingleActions {
  int? views;
  int? likes;
  int? favorites;

  SingleActions({this.views, this.likes, this.favorites});

  SingleActions.fromJson(Map<String, dynamic> json) {
    views = json['views'];
    likes = json['likes'];
    favorites = json['favorites'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['views'] = views;
    data['likes'] = likes;
    data['favorites'] = favorites;
    return data;
  }
}
